#!/bin/bash
REPO_URL=$1
USER_AGENT="Cydia/0.9 CFNetwork/758.1.6 Darwin/15.0.0"
PACKAGES=$(curl -A "$USER_AGENT" -L $REPO_URL/Packages.bz2 | bzip2 -d)

while read line; do
  if [[ $line = 'Package: '* ]]; then
    package=${line#Package: }
    echo $package
  elif [[ $line = 'Filename: '* ]]; then
    filename=${line#Filename: }
    echo "Downloading $package from $REPO_URL/$filename"
    wget -O "$package.deb" $REPO_URL/$filename
  fi
done <<< "$PACKAGES"
